//#region 通用ajax
function CommonAjax( url, funcsucobj, type, dataStr, isAsync) {
    /// <summary>
    /// 通用ajax方法
    /// </summary>
    /// <param name="funcsucobj">成功提交后执行的方法,参数:revalue,errmsg</param>
    /// <param name="funcbeforeobj">提交前执行方法</param>
    /// <param name="dataStr">ajax提交数据</param>
    /// <param name="url" type="String">指定ajax发送到的页面</param>
    /// <param name="isAsync" type="Boolean">通信访视是否为异步</param>
    $.ajax({
        type: type === undefined ? "POST" : type,
        async: isAsync === undefined ? false : isAsync,//是否是异步请求
        url: url ,
        data: dataStr,
        dataType:'json',//预期服务器返回的数据类型
        success: function (result) {
            funcsucobj(result);
        },
        cache: false
    });
}
//#endregion

//jqGrid的配置信息
$.jgrid.defaults.width = 1000;
$.jgrid.defaults.responsive = true;
$.jgrid.defaults.styleUI = 'Bootstrap';

var baseURL = "../../";

//工具集合Tools
window.T = {};

// 获取请求参数
// 使用示例
// location.href = http://localhost:8080/index.html?id=123
// T.p('id') --> 123;
var url = function(name) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
};
T.p = url;

//全局配置
$.ajaxSetup({
    dataType: "json",
    cache: false
});

//重写alert
window.alert = function(msg, callback){
    parent.layer.alert(msg, function(index){
        parent.layer.close(index);
        if(typeof(callback) === "function"){
            callback("ok");
        }
    });
}

//重写confirm式样框
window.confirm = function(msg, callback){
    parent.layer.confirm(msg, {btn: ['确定','取消']},
        function(){//确定事件
            if(typeof(callback) === "function"){
                callback("ok");
            }
        });
}

//选择一条记录
function getSelectedRow() {
    var grid = $("#jqGrid");
    var rowKey = grid.getGridParam("selrow");
    if(!rowKey){
        alert("请选择一条记录");
        return ;
    }

    var selectedIDs = grid.getGridParam("selarrrow");
    if(selectedIDs.length > 1){
        alert("只能选择一条记录");
        return ;
    }

    return selectedIDs[0];
}

function getSelectedRowProperty(property) {
    var grid = $("#jqGrid");
    var rowKey = grid.getGridParam("selrow");
    if(!rowKey){
        alert("请选择一条记录");
        return ;
    }

    var selectedIDs = grid.getGridParam("selarrrow");
    if(selectedIDs.length > 1){
        alert("只能选择一条记录");
        return ;
    }
    var rowData = grid.getRowData(selectedIDs[0]);
    return rowData[property];
}

//选择多条记录
function getSelectedRows() {
    var grid = $("#jqGrid");
    var rowKey = grid.getGridParam("selrow");
    if(!rowKey){
        alert("请选择一条记录");
        return ;
    }

    return grid.getGridParam("selarrrow");
}

function getSelectRowsProperty(property) {
    var grid = $("#jqGrid");
    var ids = grid.getGridParam("selarrrow");
    var props = [];
    for(var i=0;i<ids.length;i++){
        var rowData = grid.getRowData(ids[i]);
        props.push(rowData[property]);
    }
    return props;
}

//判断是否为空
function isBlank(value) {
    return !value || !/\S/.test(value)
}